using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class mapPonit : MonoBehaviour
{
    public Transform MinimapCam;
    public float MinimapSize;
    Vector3 TempV3;

    void Update()
    {
        TempV3.x = transform.parent.transform.position.x;
        TempV3.y = transform.parent.transform.position.y;
        TempV3.z = -100;
        transform.position = TempV3;
    }

    void LateUpdate()
    {
        transform.position = new Vector3(
            Mathf.Clamp(transform.position.x, MinimapCam.position.x - MinimapSize, MinimapSize + MinimapCam.position.x),
            Mathf.Clamp(transform.position.y, MinimapCam.position.y - MinimapSize, MinimapSize + MinimapCam.position.y),
            -100
        );
        if (transform.parent.transform.position.x != transform.position.x|| transform.parent.transform.position.y != transform.position.y)
        {

            float angle = Mathf.Atan2(MinimapCam.position.x - transform.position.x
                , MinimapCam.position.y - transform.position.y) * Mathf.Rad2Deg;


            Quaternion quaternion = Quaternion.Euler(new Vector3(0, 0, -angle));
            transform.rotation = quaternion;

        }
        else
        {
            Quaternion quaternion = Quaternion.Euler(new Vector3(0, 0,0));
            transform.rotation = quaternion;
        }

    }
}
